Exemplo n.º 1
0
        public ActionResult Create(ChatTemplateModels model)
        {
            try
            {
                if (string.IsNullOrEmpty(model.Name))
                {
                    ModelState.AddModelError("Name", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Name is required"));
                }

                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                //====================
                string msg = "";
                model.ListOrgID = CurrentUser.ListOrganizationId;
                bool result = _factory.InsertOrUpdateChattingTemplate(model, ref msg);
                if (result)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("Name", msg);
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("ChattingTemplateCreate_error", ex);
                return(new HttpStatusCodeResult(400, ex.Message));
            }
        }
Exemplo n.º 2
0
        public ActionResult Edit(ChatTemplateModels model)
        {
            try
            {
                if (string.IsNullOrEmpty(model.Name))
                {
                    ModelState.AddModelError("Name", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Name is required"));
                }

                if (!ModelState.IsValid)
                {
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(PartialView("_Edit", model));
                }
                //====================
                string msg = "";
                model.ListOrgID = CurrentUser.ListOrganizationId;
                var result = _factory.InsertOrUpdateChattingTemplate(model, ref msg);
                if (result)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    //return PartialView("_Edit", model);
                    ModelState.AddModelError("Name", msg);
                    return(PartialView("_Edit", model));
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("Chatting_Edit : ", ex);
                return(new HttpStatusCodeResult(400, ex.Message));
            }
        }
Exemplo n.º 3
0
        public ActionResult Import()
        {
            ChatTemplateModels model = new ChatTemplateModels();

            model.ListMerchants = CurrentUser.ListOrganizations != null?CurrentUser.ListOrganizations.Select(ss => new SelectListItem()
            {
                Value = ss.ID, Text = ss.Name
            }).ToList() : new List <SelectListItem>();

            return(View(model));
        }
Exemplo n.º 4
0
        public ActionResult Export(ChatTemplateModels model)
        {
            try
            {
                //if (model.ListType == null)
                //{
                //    ModelState.AddModelError("ListType", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Please choose type."));
                //    return View(model);
                //}

                XLWorkbook wb = new XLWorkbook();
                var        ws = wb.Worksheets.Add("Sheet1");

                StatusResponse response = _factory.Export(ref ws, CurrentUser.ListOrganizationId, model.ChatTemplateType);

                if (!response.Status)
                {
                    ModelState.AddModelError("", response.MsgError);
                    return(View(model));
                }

                ViewBag.wb = wb;
                Response.Clear();
                Response.ClearContent();
                Response.ClearHeaders();
                Response.Charset         = System.Text.UTF8Encoding.UTF8.WebName;
                Response.ContentEncoding = System.Text.UTF8Encoding.UTF8;
                Response.ContentType     = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AddHeader("content-disposition", String.Format(@"attachment;filename={0}.xlsx", CommonHelper.GetExportFileName("Chatting Template").Replace(" ", "_")));

                using (var memoryStream = new System.IO.MemoryStream())
                {
                    wb.SaveAs(memoryStream);
                    memoryStream.WriteTo(HttpContext.Response.OutputStream);
                    memoryStream.Close();
                }
                HttpContext.Response.End();
                return(RedirectToAction("Export"));
            }
            catch (Exception e)
            {
                NSLog.Logger.Error("Chatting Template Export : ", e);
                //return new HttpStatusCodeResult(400, e.Message);
                //ModelState.AddModelError("ListStores", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Import file have error."));
                return(View(model));
            }
        }
Exemplo n.º 5
0
 public ChatTemplateModels GetDetail(string id)
 {
     try
     {
         ChatTemplateModels model = _factory.GetListChattingTemplate(CurrentUser.ListOrganizationId, false, null, id).FirstOrDefault();
         if (model == null)
         {
             model = new ChatTemplateModels();
         }
         return(model);
     }
     catch (Exception ex)
     {
         NSLog.Logger.Error("ChattingGetDetail_Error:", ex);
         return(null);
     }
 }
Exemplo n.º 6
0
 public ActionResult Delete(ChatTemplateModels model)
 {
     try
     {
         string msg    = "";
         var    result = _factory.DeleteChatting(model.ID, ref msg);
         if (!result)
         {
             ModelState.AddModelError("Name", msg);
             Response.StatusCode = (int)HttpStatusCode.BadRequest;
             return(PartialView("_Delete", model));
         }
         return(new HttpStatusCodeResult(HttpStatusCode.OK));
     }
     catch (Exception ex)
     {
         NSLog.Logger.Error("Chatting_Delete : ", ex);
         ModelState.AddModelError("Name", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Have an error when you delete a Chatting Template"));
         Response.StatusCode = (int)HttpStatusCode.BadRequest;
         return(PartialView("_Delete", model));
     }
 }
Exemplo n.º 7
0
        public bool InsertOrUpdateChattingTemplate(ChatTemplateModels model, ref string msg)
        {
            try
            {
                ChatTemplateApiModels paraBody = new ChatTemplateApiModels();
                paraBody.AppKey      = Commons.AppKey;
                paraBody.AppSecret   = Commons.AppSecret;
                paraBody.CreatedUser = Commons.CreateUser;

                paraBody.ListOrgID       = model.ListOrgID;
                paraBody.ChatTemplateDTO = model;
                NSLog.Logger.Info("InsertOrUpdateChattingTemplate_Input", paraBody);
                //====================
                var result = (ResponseApiModels)ApiResponse.Post <ResponseApiModels>(Commons.ChattingCreateOrEdit, null, paraBody);
                if (result != null)
                {
                    if (result.Success)
                    {
                        return(true);
                    }
                    else
                    {
                        NSLog.Logger.Info("InsertOrUpdateChattingTemplate_Output", result);
                        return(false);
                    }
                }
                else
                {
                    NSLog.Logger.Info("InsertOrUpdateChattingTemplate_Output", result);
                    return(false);
                }
            }
            catch (Exception e)
            {
                NSLog.Logger.Error("InsertOrUpdateChattingTemplate_Error: ", e);
                return(false);
            }
        }
Exemplo n.º 8
0
        public ActionResult Create()
        {
            ChatTemplateModels model = new ChatTemplateModels();

            return(View(model));
        }
Exemplo n.º 9
0
        public ActionResult Import(ChatTemplateModels model)
        {
            try
            {
                if (model.MerchantsSelected == null)
                {
                    ModelState.AddModelError("MerchantsSelected", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Please choose merchant"));
                    model.ListMerchants = CurrentUser.ListOrganizations != null?CurrentUser.ListOrganizations.Select(ss => new SelectListItem()
                    {
                        Value = ss.ID, Text = ss.Name
                    }).ToList() : new List <SelectListItem>();

                    return(View(model));
                }
                if (model.ExcelUpload == null || model.ExcelUpload.ContentLength <= 0)
                {
                    ModelState.AddModelError("ExcelUpload", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Excel filename cannot be null"));
                    model.ListMerchants = CurrentUser.ListOrganizations != null?CurrentUser.ListOrganizations.Select(ss => new SelectListItem()
                    {
                        Value = ss.ID, Text = ss.Name
                    }).ToList() : new List <SelectListItem>();

                    return(View(model));
                }

                ImportModel    importModel = new ImportModel();
                string         msg         = "";
                StatusResponse response    = _factory.Import(model.ExcelUpload, model.MerchantsSelected, ref importModel, ref msg);
                if (!response.Status)
                {
                    ModelState.AddModelError("", response.MsgError);
                    model.ListMerchants = CurrentUser.ListOrganizations != null?CurrentUser.ListOrganizations.Select(ss => new SelectListItem()
                    {
                        Value = ss.ID, Text = ss.Name
                    }).ToList() : new List <SelectListItem>();

                    return(View(model));
                }

                // Delete File Excel and File Zip Image
                CommonHelper.DeleteFileFromServer(CommonHelper.GetFilePath(model.ExcelUpload));

                //if (!ModelState.IsValid)
                //    return View(model);

                if (msg.Equals(""))
                {
                    return(View("ImportDetail", importModel));
                }
                else
                {
                    NSLog.Logger.Info("Chatting_Import :", msg);
                    ModelState.AddModelError("ExcelUpload", msg);
                    model.ListMerchants = CurrentUser.ListOrganizations != null?CurrentUser.ListOrganizations.Select(ss => new SelectListItem()
                    {
                        Value = ss.ID, Text = ss.Name
                    }).ToList() : new List <SelectListItem>();

                    return(View(model));
                }
            }
            catch (Exception e)
            {
                NSLog.Logger.Error("Chatting_Import_Error : ", e);
                ModelState.AddModelError("ExcelUpload", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Import file have error."));
                return(View(model));
            }
        }
Exemplo n.º 10
0
        public PartialViewResult Delete(string id)
        {
            ChatTemplateModels model = GetDetail(id);

            return(PartialView("_Delete", model));
        }
Exemplo n.º 11
0
        public PartialViewResult Edit(string id)
        {
            ChatTemplateModels model = GetDetail(id);

            return(PartialView("_Edit", model));
        }
Exemplo n.º 12
0
        public new PartialViewResult View(string id)
        {
            ChatTemplateModels model = GetDetail(id);

            return(PartialView("_View", model));
        }
Exemplo n.º 13
0
        public StatusResponse Import(HttpPostedFileBase excelFile, List <string> ListOrgID, ref ImportModel importModel, ref string msg)
        {
            StatusResponse Response = new StatusResponse();
            DataTable      dt       = new DataTable();

            FileInfo[] lstFileImg = new FileInfo[] { };
            Response = ProcessDataImport(ref dt, excelFile, "SChattingTeamplate.xlsx", out lstFileImg);

            if (!Response.Status)
            {
                msg = Response.MsgError;
                return(Response);
            }

            ImportItem itemErr    = null;
            bool       flagInsert = true;
            string     msgError   = "";

            List <ChatTemplateModels> listData = new List <ChatTemplateModels>();

            foreach (DataRow row in dt.Rows)
            {
                try
                {
                    flagInsert = true;
                    msgError   = "";

                    string rowText = "";

                    for (int i = 0; i < dt.Columns.Count; i++)
                    {
                        rowText += row[i].ToString().Trim();
                    }

                    if (string.IsNullOrEmpty(rowText))
                    {
                        continue;
                    }

                    ChatTemplateModels model = new ChatTemplateModels();
                    model.Index = Convert.ToInt32(row[0]);
                    // 1 - Name
                    model.Name = row[1].ToString().Trim().Replace("  ", " ");
                    // 2 - IsActive (status)
                    model.IsActive = GetBoolValue(dt.Columns[2].ColumnName.Replace("#", "."), row[0].ToString(), row[2].ToString());
                    //description
                    model.Description      = row[3].ToString().Trim().Replace("  ", " ");
                    model.ChatTemplateType = row[4].ToString().Trim().ToLower().Replace("  ", " ").Equals("artiste") ? (int)Commons.EChatTemplate.Artiste : (int)Commons.EChatTemplate.Customer;
                    //==============

                    if (flagInsert)
                    {
                        listData.Add(model);
                    }
                    else
                    {
                        itemErr      = new ImportItem();
                        itemErr.Name = model.Name;
                        itemErr.ListFailStoreName.Add("");
                        itemErr.ListErrorMsg.Add(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Row") + ":" + model.Index + msgError);
                        importModel.ListImport.Add(itemErr);
                    }
                }
                catch (Exception e)
                {
                    NSLog.Logger.Error("Import Chatting Error", e);
                    importModel.ListImport.Add(new ImportItem {
                        Name = _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Chatting Template"), ListFailStoreName = ListOrgID, ListErrorMsg = new List <string> {
                            e.Message
                        }
                    });
                }
            }
            Response.Status = true;
            //=====================

            //try
            //{
            ChatTemplateApiModels paraBody = new ChatTemplateApiModels();

            paraBody.AppKey       = Commons.AppKey;
            paraBody.AppSecret    = Commons.AppSecret;
            paraBody.CreatedUser  = Commons.CreateUser;
            paraBody.ListOrgID    = ListOrgID;
            paraBody.ListTemplate = listData;
            //====================
            NSLog.Logger.Info("Import Chatting", paraBody);
            var result = (ResponseApiModels)ApiResponse.Post <ResponseApiModels>(Commons.ChattingImport, null, paraBody);

            NSLog.Logger.Info("Import Chatting result", paraBody);
            if (result != null)
            {
                dynamic data       = result.Data;
                var     lstC       = data["ListProperty"];
                var     lstContent = JsonConvert.SerializeObject(lstC);
                var     listError  = JsonConvert.DeserializeObject <List <ImportResult> >(lstContent);

                foreach (ImportResult itemError in listError)
                {
                    ImportItem item = new ImportItem();
                    item.Name = itemError.Property;
                    item.ListFailStoreName.Add(itemError.StoreName);
                    item.ListErrorMsg.Add(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Row") + ": " + itemError.Index + "<br/>"
                                          + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(itemError.Error));
                    importModel.ListImport.Add(item);
                }
                if (importModel.ListImport.Count == 0)
                {
                    ImportItem item = new ImportItem();
                    item.Name = _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Chat List");
                    item.ListSuccessStoreName.Add(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Import Tax Successful"));
                    importModel.ListImport.Add(item);
                }
            }
            return(Response);
        }