Exemplo n.º 1
0
        public async Task <DNActionResult> DeleteAsync(BaseModel model, string profileno, string userno, string shopNo)
        {
            DNItem item   = (DNItem)model;
            var    result = new DNActionResult();

            if (item.Itemnumber == 0)
            {
                result.ValidationErrors.Add("ItemNumber", "itemdoesnotexist");
            }
            result.Notification = result.ValidationErrors.Count == 0 ? NotificationType.success : NotificationType.warning;
            if (result.Notification == NotificationType.success)
            {
                result.Action = DNActionCommand.Delete;
                try {
                    string url            = string.Format(DNGlobalProperties.Current.ERPAPIAddress + @"/back_office/item/deleteitem?itemnumber={0}&userno={1}&profileno={2}&shopno={2}", item.Itemnumber, userno, profileno, shopNo);
                    var    httpWebRequest = await DNAPIHandler.Current.GetWebRequestAsync("GET", url);

                    var httpResponse = (HttpWebResponse)await httpWebRequest.GetResponseAsync();

                    if (httpResponse.StatusCode == HttpStatusCode.OK)
                    {
                        using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) {
                            bool isvalid = streamReader.ReadToEnd().ToBool();
                            result.Notification = isvalid ? NotificationType.success : NotificationType.error;
                        }
                    }
                } catch (Exception exc) {
                    string error = exc.Message + exc.StackTrace;
                }
            }
            return(await Task.FromResult(result));
        }
Exemplo n.º 2
0
        public async Task <DNActionResult> SaveAddtionalDetailsAsync(BaseModel model)
        {
            DNItem item   = (DNItem)model;
            var    result = new DNActionResult();

            result.ValidationErrors = Validate(item);
            result.Notification     = result.ValidationErrors.Count == 0 ? NotificationType.success : NotificationType.warning;
            if (result.Notification == NotificationType.success)
            {
                result.Action = DNActionCommand.Save;
                try {
                    var json = JsonConvert.SerializeObject(item, new JsonSerializerSettings()
                    {
                        Formatting = Newtonsoft.Json.Formatting.Indented, NullValueHandling = NullValueHandling.Ignore
                    });
                    var httpResponse = (HttpWebResponse)await DNAPIHandler.Current.PostResponseAsync(string.Format(DNGlobalProperties.Current.ERPAPIAddress + @"/back_office/item/additional_details/"), json);

                    if (httpResponse.StatusCode == HttpStatusCode.OK)
                    {
                        using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) {
                            result.ReturnModel = JsonConvert.DeserializeObject <DNItem>(streamReader.ReadToEnd());
                            if (result.ReturnModel == null)
                            {
                                result.Notification = NotificationType.error;
                            }
                        }
                    }
                    else
                    {
                        result.Notification = NotificationType.error;
                    }
                } catch (Exception exc) {
                    string error = exc.Message + exc.StackTrace;
                }
            }
            return(await Task.FromResult(result));
        }