Example #1
0
        public JsonResult Manage(MDummyModel item)
        {
            UserInfoModel     userInfo = (UserInfoModel)GeneralFunctions.GetSession(Configs.session);
            ResultStatusModel result   = new ResultStatusModel();

            item.UserCreated  = userInfo.UserName;
            item.UserModified = userInfo.UserName;

            if (ModelState.IsValid)
            {
                try
                {
                    string id_out = "";
                    if (item.PlanID == 0)
                    {
                        result = uow.DummyRepository.CUD_Dummy(item, "c", out id_out);
                    }

                    if (!result.issuccess)
                    {
                        ModelState.AddModelError("Failed", result.err_msg);
                    }
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("Failed", e.Message);
                }
            }
            List <string> Error = (from m in ModelState
                                   where m.Value.Errors.Any()
                                   select m.Value.Errors[0].ErrorMessage).ToList();

            return(Json(new { Error = Error, data = item }, JsonRequestBehavior.DenyGet));
        }
Example #2
0
        public JsonResult Delete(int id = 0)
        {
            UserInfoModel       userInfo = (UserInfoModel)GeneralFunctions.GetSession(Configs.session);
            MGroupUserMenuModel item     = new MGroupUserMenuModel();

            item.GroupUserMenuID = id;
            item.UserCreated     = userInfo.UserName;
            item.UserModified    = userInfo.UserName;

            ResultStatusModel result = new ResultStatusModel();

            ModelState.Clear();

            try
            {
                string id_out = "";
                result = uow.GroupUserMenuRepository.CUD_GroupUserMenu(item, "d", out id_out);
                if (!result.issuccess)
                {
                    ModelState.AddModelError("Failed", result.msg);
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("Failed", e.Message);
            }

            List <string> Error = (from m in ModelState
                                   where m.Value.Errors.Any()
                                   select m.Value.Errors[0].ErrorMessage).ToList();

            return(Json(new { Error = Error, data = id }, JsonRequestBehavior.DenyGet));
        }
Example #3
0
 public ResultModel(T value, ResultCode code = ResultCode.Ok)
 {
     Value  = value;
     Status = new ResultStatusModel()
     {
         Code = code
     };
 }
        public void ValidData_ModelAreCorrect()
        {
            //prepare
            var code    = ResultCode.Ok;
            var message = "message";
            var details = "details";

            //action
            var action = new ResultStatusModel()
            {
                Code    = code,
                Message = message,
                Details = details
            };

            //check
            Assert.Equal(ResultCode.Ok, action.Code);
            Assert.Equal("message", action.Message);
            Assert.Equal("details", action.Details);
        }
Example #5
0
        public JsonResult Manage(MVesselModel item)
        {
            //UserInfoModel userInfo = (UserInfoModel)GeneralFunctions.GetSession(Configs.session);
            ResultStatusModel result = new ResultStatusModel();

            //item.UserCreated = userInfo.UserName;
            //item.UserModified = userInfo.UserName;
            result = uow.VesselRepository.CUD_Vessel(item);
            //if (ModelState.IsValid)
            //{
            //    try
            //    {
            //        string id_out = "";
            //        if (item.GroupUserMenuID == 0)
            //        {
            //            result = uow.GroupUserMenuRepository.CUD_GroupUserMenu(item, "c", out id_out);
            //        }
            //        else
            //        {
            //            result = uow.GroupUserMenuRepository.CUD_GroupUserMenu(item, "u", out id_out);
            //        }

            //        if (!result.issuccess)
            //        {
            //            ModelState.AddModelError("Failed", result.err_msg);
            //        }
            //    }
            //    catch (Exception e)
            //    {
            //        ModelState.AddModelError("Failed", e.Message);
            //    }
            //}
            //List<string> Error = (from m in ModelState
            //                      where m.Value.Errors.Any()
            //                      select m.Value.Errors[0].ErrorMessage).ToList();

            return(Json(new { data = item }, JsonRequestBehavior.DenyGet));
        }
Example #6
0
        public static ResultStatusModel doSendMail(string toEmail, string cc, string bcc,
                                                   string subject, string messages, List <string> fileAttachments = null)
        {
            bool result = false;
            ResultStatusModel output = new ResultStatusModel();

            output.issuccess = true;
            try
            {
                //clsConfig cfg = new clsConfig();

                // Revised by Robin Frans ( check settingan email apakah ON atau OFF )
                string EmailPower = Configs.Mail_Power;
                if (EmailPower.ToUpper().Trim() != "ON")
                {
                    //clsLog.writeToLog("CommonService", "Setting email is OFF. Failed sending email to " + toEmail);
                    output.issuccess = false;
                    return(output);
                }



                string smtp        = Configs.Mail_smtp;
                string port        = Configs.Mail_port;
                string from        = Configs.Mail_from;
                string fromDisplay = Configs.Mail_fromDisplayName;
                string cfgBcc      = Configs.Mail_Bcc;

                //clsLog.writeToLog("CommonService", "smtp = " + smtp);
                //clsLog.writeToLog("CommonService", "port = " + port);
                //clsLog.writeToLog("CommonService", "from = " + from);
                //clsLog.writeToLog("CommonService", "Bcc = " + cfgBcc);

                //clsLog.WriteToTextFile("doSendMail", "Bo.doSendMail", "smtp = " + smtp);
                //clsLog.WriteToTextFile("doSendMail", "Bo.doSendMail", "port = " + port);
                //clsLog.WriteToTextFile("doSendMail", "Bo.doSendMail", "from = " + from);
                //clsLog.WriteToTextFile("doSendMail", "Bo.doSendMail", "Bcc = " + cfgBcc);

                MailMessage mail   = new MailMessage();
                SmtpClient  client = new SmtpClient(smtp, Convert.ToInt32(port));

                if (!string.IsNullOrEmpty(toEmail))
                {
                    string[] sToEmail = toEmail.Split(";".ToCharArray());
                    int      length   = sToEmail.Length;
                    for (int i = 0; i < length; i++)
                    {
                        try
                        {
                            mail.To.Add(sToEmail[i].ToString() + Configs.Mail_Dummy);
                        }
                        catch (Exception ex)
                        {
                            //throw ex;
                        }
                    }
                }
                else
                {
                    output.issuccess = false;
                    output.err_msg   = "Tujuan email tidak ditemukan.";
                    return(output);
                }



                if (!string.IsNullOrEmpty(cc))
                {
                    string[] ccL = cc.Split(";".ToCharArray());
                    int      len = ccL.Length;
                    for (int j = 0; j < len; j++)
                    {
                        try
                        {
                            mail.CC.Add(ccL[j].ToString() + Configs.Mail_Dummy);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }

                if (!string.IsNullOrEmpty(cfgBcc))
                {
                    string[] sBcc = cfgBcc.Split(";".ToCharArray());
                    for (int k = 0; k < sBcc.Length; k++)
                    {
                        if (sBcc[k].ToString().Trim() != "")
                        {
                            try
                            {
                                mail.Bcc.Add(sBcc[k].ToString().Trim());
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                }
                if (!string.IsNullOrEmpty(bcc))
                {
                    string[] sBcc = bcc.Split(";".ToCharArray());
                    for (int k = 0; k < sBcc.Length; k++)
                    {
                        if (sBcc[k].ToString().Trim() != "")
                        {
                            try
                            {
                                mail.Bcc.Add(sBcc[k].ToString().Trim() + Configs.Mail_Dummy);
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                }

                mail.From       = new System.Net.Mail.MailAddress(from, fromDisplay);
                mail.Subject    = subject;
                mail.Body       = messages;
                mail.IsBodyHtml = true;

                if (fileAttachments != null)
                {
                    foreach (string item in fileAttachments)
                    {
                        Attachment data = new Attachment(item, MediaTypeNames.Application.Octet);
                        mail.Attachments.Add(data);
                    }
                }

                client.UseDefaultCredentials = false;
                client.EnableSsl             = false;
                client.Send(mail);

                if (mail.Attachments != null)
                {
                    for (Int32 i = mail.Attachments.Count - 1; i >= 0; i--)
                    {
                        mail.Attachments[i].Dispose();
                    }
                    mail.Attachments.Clear();
                    mail.Attachments.Dispose();
                }
                mail.Dispose();
                mail = null;

                result           = true;
                output.issuccess = true;
            }
            catch (Exception ex)
            {
                string innerEx = GeneralFunctions.GetExceptionMessage(ex);
                result           = false;
                output.issuccess = false;
                output.err_msg   = ex.Message + " (Inner Ex : " + innerEx + ")";
            }
            //return result;
            return(output);
        }
        public async Task <JsonResult> Manage(UserModel item)
        {
            UserInfoModel     userInfo = (UserInfoModel)GeneralFunctions.GetSession(Configs.session);
            ResultStatusModel result   = new ResultStatusModel();

            item.UserCreated  = userInfo.UserName;
            item.UserModified = userInfo.UserName;

            if (item.UserID == 0 && string.IsNullOrEmpty(item.Password))
            {
                ModelState.AddModelError("Password", "Password wajib diisi!");
            }

            //try
            //{
            //    using (HttpClient client = new HttpClient())
            //    {
            //        client.BaseAddress = new Uri("http://10.126.20.22/ws_NIKSAP/Service1.asmx/");
            //        HttpResponseMessage response = new HttpResponseMessage();
            //        response = await client.GetAsync("GetNIKSAP?employee_code=" + item.Nik + "&userparam=sap&passparam=JOYketC0rdA/F4MBzx5BEA==");
            //        var data = await response.Content.ReadAsStringAsync();
            //        XElement convertXml = XElement.Parse(data);
            //        if (string.IsNullOrEmpty(convertXml.Value))
            //        {
            //            ModelState.AddModelError("Nik", "Nik tidak ditemukan!");
            //        }
            //    }
            //}
            //catch (Exception ex)
            //{
            //    ModelState.AddModelError("User", ex.Message);
            //}

            if (ModelState.IsValid)
            {
                try
                {
                    MUserVM user = new MUserVM();
                    user.UserID        = item.UserID;
                    user.Email         = item.Email;
                    user.GroupUserID   = item.GroupUserID.ToString();
                    user.GroupUserName = item.GroupUserName;
                    user.IsDeleted     = false;
                    user.Nik           = item.Nik;
                    user.OfficialName  = item.OfficialName;
                    user.UserName      = item.UserName;
                    if (item.UserID == 0)
                    {
                        user.Password = Helper.Encryption.EncryptRegular(Configs.KeyEncrypt, item.Password);
                    }
                    user.UserCreated  = userInfo.UserName;
                    user.UserModified = userInfo.UserName;

                    string id_out = "";
                    if (item.UserID == 0)
                    {
                        result = uow.UserRepository.CUD_User(user, "c", out id_out);
                    }
                    else
                    {
                        result = uow.UserRepository.CUD_User(user, "u", out id_out);
                    }

                    if (!result.issuccess)
                    {
                        ModelState.AddModelError("Failed", result.err_msg);
                    }
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("Failed", e.Message);
                }
            }
            List <string> Error = (from m in ModelState
                                   where m.Value.Errors.Any()
                                   select m.Value.Errors[0].ErrorMessage).ToList();

            return(Json(new { Error = Error, data = item }, JsonRequestBehavior.DenyGet));
        }